# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def binaryTreePaths(self, root: TreeNode) -> list:
        if not root:
            return []
        self.res = []
        self.search(root, "")
        return self.res

    def search(self, root: TreeNode, s_in: str):
        if not root.left and not root.right:
            self.res.append(s_in + str(root.val))
            return
        if root.left:
            self.search(root.left, s_in + str(root.val) + "->")
        if root.right:
            self.search(root.right, s_in + str(root.val) + "->")
